<template>
    <div style="height:100%;width:100%;position:relative;overflow: hidden;">
        <div>
            <div class="page-top" style="border:1px solid #CCC">
                <div style="min-width: 920px;">
                    <div class="page-top-info">
                        <div class="search-title">创建日期</div>
                        <el-date-picker v-model="searchParam.startdt" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" clearable style="width:130px"></el-date-picker>
                        <span style="margin: 0 5px;">-</span>
                        <el-date-picker v-model="searchParam.enddt" type="date" placeholder="结束日期" value-format="yyyy-MM-dd" clearable style="width:130px"></el-date-picker>
                        <!-- <div class="search-title">病历号</div>
                        <div class="search-text">
                            <el-input v-model="searchParam.txtpatno" size="mini" style="width:130px" clearable></el-input>
                        </div> -->
                        <div class="search-title">条码号</div>
                        <div class="search-text">
                            <el-input v-model="searchParam.txtbarcode" size="mini" style="width:130px" clearable @keyup.enter.native="queryList"></el-input>
                        </div>
                        <div class="search-title">病人类型</div>
                        <div class="search-text">
                            <rm-ddl-common datatype="seccode" kindno="PT" dataname="病用户类型" v-model="searchParam.txtpattype" width="130px" @change="queryList"></rm-ddl-common>
                        </div>
                        <div class="search-title">创建用户</div>
                        <div class="search-text">
                            <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchParam.txtcreateuser" width="130px" @change="queryList"></rm-ddl-common>
                        </div>
                    </div>
                    <div class="top-deal">
                        <el-button icon="el-icon-search" type="primary" @click="queryList" :disabled="changeflag">查询</el-button>
                        <el-button icon="el-icon-plus" @click="MainOpenDialog(1)" :disabled="changeflag">新增</el-button>
                        <el-button icon="el-icon-delete" @click="MainOpenDialog(2)" :disabled="changeflag">删除</el-button>
                        <el-button icon="el-icon-document" @click="MainOpenDialog(3)" :disabled="!changeflag">保存</el-button>
                        <el-button icon="el-icon-close" @click="MainOpenDialog(4)" :disabled="!changeflag">取消</el-button>
                        <el-button icon="el-icon-printer" @click="btnPrint" :disabled="changeflag">打印</el-button>
                        <el-button icon="el-icon-setting" @click="btnSet">设置</el-button>
                    </div>
                </div>
            </div>
            <div class="pagecenter">
                <div class="pagecenter-left">
                    <vxe-table ref="lxTable" :data.sync="reqMasterList" :loading="reqMasterLoading" class="mytable-style" border 
                        size="mini" show-header-overflow highlight-current-row resizable stripe header-align="center" height="auto" 
                        show-overflow highlight-hover-column :row-class-name="rowClassName" @current-change="currentChangeEvent" 
                        :select-config="{reserve: true}" :sort-config="{trigger: 'cell',checkAll: true, reserve: true }">
                        <vxe-table-column type="selection" width="45" align="center" v-if="chkSupportMutiplePrint=='1'"></vxe-table-column>
                        <vxe-table-column field="hospname" title="送检医院" width="120"></vxe-table-column>
                        <vxe-table-column field="pat_typename" title="来源" width="60"></vxe-table-column>
                        <vxe-table-column field="create_dt" title="登记时间" width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="pat_name" title="姓名" width="66"></vxe-table-column>
                        <vxe-table-column field="pat_no" title="病历号" width="90"></vxe-table-column>
                        <vxe-table-column field="req_groupna" title="分单类别" width="88"></vxe-table-column>
                        <vxe-table-column field="barcode" title="条码号" width="117"></vxe-table-column>
                        <vxe-table-column field="emer_flag" title="加急" width="50">
                            <template v-slot="{row}">
                                <span style="color:red">{{row.emer_flag=="1"?"急":""}}</span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="sample_items" title="申请项目(简称，部分)" width="203"></vxe-table-column>
                        <vxe-table-column field="base_amount" title="应收金额" width="75" align="right"></vxe-table-column>
                        <vxe-table-column field="req_statname" title="申请状态" width="80"></vxe-table-column>
                        <vxe-table-column field="labadd" title="实验室增加标志" width="75" align="center">
                            <template v-slot="{row}">
                                <el-checkbox v-model="row.labadd" true-label="1" false-label="0" disabled></el-checkbox>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="req_deptname" title="申请科室" width="94"></vxe-table-column>
                        <vxe-table-column field="req_docname" title="申请医生" width="80"></vxe-table-column>
                        <vxe-table-column field="req_bedno" title="床号" width="74"></vxe-table-column>
                        <vxe-table-column field="specimen_name" title="标本类型" width="80"></vxe-table-column>
                        <vxe-table-column field="pat_sexname" title="性别" width="50" align="center"></vxe-table-column>
                        <vxe-table-column field="pat_agestr" title="年龄" width="50"></vxe-table-column>
                        <vxe-table-column field="create_username" title="创建用户" width="80"></vxe-table-column>
                        <vxe-table-column field="print_dt" title="打印/执行时间 " width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="print_username" title="打印/执行用户 " width="101"></vxe-table-column>
                        <vxe-table-column field="print_count" title="打印次数" width="78" align="center"></vxe-table-column>
                        <vxe-table-column field="sampled_dt" title="采样时间" width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="sampled_username" title="采样用户" width="80"></vxe-table-column>
                        <vxe-table-column field="req_dt" title="申请日期" width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="prereport_dt" title="预出报告时间 " width="108" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="pat_diag" title="临床诊断" width="110"></vxe-table-column>
                        <vxe-table-column field="pat_id" title="病用户ID号" width="87"></vxe-table-column>
                        <vxe-table-column field="inp_date" title="入院日期" width="123" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="recieve_dt" title="接收时间" width="126" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="recieve_username" title="接收用户" width="80"></vxe-table-column>
                        <vxe-table-column field="charge_dt" title="计价时间" width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="charge_username" title="计价用户" width="80"></vxe-table-column>
                        <vxe-table-column field="amount" title="实收金额" width="80" align="right"></vxe-table-column>
                        <vxe-table-column field="charge_flag" title="计价标志" width="73"></vxe-table-column>
                        <vxe-table-column field="test_dt" title="上机时间" width="100" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="test_username" title="上机用户" width="90"></vxe-table-column>
                        <vxe-table-column field="report_dt" title="报告时间" width="134" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="report_username" title="检验医生姓名" width="102"></vxe-table-column>
                        <vxe-table-column field="rechk_username" title="核对医生姓名" width="95"></vxe-table-column>
                        <vxe-table-column field="alter_flag" title="报警" width="52"></vxe-table-column>
                        <vxe-table-column field="saleman" title="销售员" width="80"></vxe-table-column>
                        <vxe-table-column field="pat_cardno" title="就诊卡号" width="100"></vxe-table-column>
                        <vxe-table-column field="req_comm" title="医生备注" width="127"></vxe-table-column>
                        <vxe-table-column field="pat_birth" title="生日" width="90" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="pat_ageyear" title="年龄岁数" width="80"></vxe-table-column>
                        <vxe-table-column field="inp_id" title="住院标识/就诊号" width="106"></vxe-table-column>
                        <vxe-table-column field="pat_diag_icd" title="诊断的ICD10编码 " width="121"></vxe-table-column>
                        <vxe-table-column field="pat_address" title="地址" width="155"></vxe-table-column>
                        <vxe-table-column field="pat_phone" title="联系电话" width="124"></vxe-table-column>
                        <vxe-table-column field="charge_typename" title="收费类型" width="80"></vxe-table-column>
                        <vxe-table-column field="req_wardname" title="所属病区" width="105"></vxe-table-column>
                        <vxe-table-column field="cancel_dt" title="作废时间" width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="cancel_username" title="作废用户" width="105"></vxe-table-column>
                        <vxe-table-column field="reject_dt" title="踢回时间" width="130" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="reject_username" title="踢回用户" width="80"></vxe-table-column>
                        <vxe-table-column field="reject_reason" title="踢回原因" width="95" align="center"></vxe-table-column>
                        <vxe-table-column field="reject_count" title="踢回次数" width="80"></vxe-table-column>
                        <vxe-table-column field="specimen_code" title="标本类型代码" width="100"></vxe-table-column>
                        <vxe-table-column field="sample_detail" title="标本备注说明" width="120"></vxe-table-column>
                        <vxe-table-column field="req_reason" title="送检目的" width="107"></vxe-table-column>
                        <vxe-table-column field="req_groupid" title="分单类别ID" width="80"></vxe-table-column>
                        <vxe-table-column field="report_id" title="报告单ID" width="80"></vxe-table-column>
                        <vxe-table-column field="report_user" title="检验医生" width="80"></vxe-table-column>
                        <vxe-table-column field="rechk_user" title="核对医生" width="80"></vxe-table-column>
                        <vxe-table-column field="inlib_status" title="入库状态" width="80"></vxe-table-column>
                        <vxe-table-column field="library_id" title="所在库位ID" width="87"></vxe-table-column>
                        <vxe-table-column field="reqtype" title="申请单类别" width="88"></vxe-table-column>
                        <vxe-table-column field="tube_color" title="试管颜色" width="80"></vxe-table-column>
                    </vxe-table>
                </div>
                <div class="pagecenter-right">
                    <div v-if="nodata" class="show-area" :style="{height:formheight+'px'}"></div>
                    <div style="height: 100%;">
                        <div style="border:1px solid #CCC;overflow:auto" :style="{height:formheight+'px'}" class="myclass">
                            <el-form ref="masterListForm" :model="masterParam" :disabled="nodata" size="mini" class="table2style">
                                <table style="width:100%;font-size:12px;font-weight:500">
                                    <tr>
                                        <td>
                                            <span class="column-item must-param" style="width:70px" align="right">条码号</span>
                                            <span class="column-item" style="width:140px">
                                                <el-input v-model="reqBack.barcode" style="width:100%" ref="barcode" @keyup.enter.native="backNextFocus('down', 1)" @input="hasChange" @keyup.down.native="backNextFocus('down', 1)"></el-input><!-- :disabled="item.enabled=='1'"-->
                                            </span>
                                        </td>
                                        <td>
                                            <span class="column-item must-param" style="width:70px" align="right">退回原因</span>
                                            <span class="column-item" style="width:140px">
                                                <el-input v-model="reqBack.reject_reason" style="width:100%" ref="inputbackreason" @keyup.enter.native="backNextFocus('down', 2)" @input="hasChange" @dblclick.native="opendialog('refusereason','REFUSEREASON')" @keyup.space.native="opendialog('refusereason','REFUSEREASON')" @keyup.up.native="backNextFocus('up', 2)" @keyup.down.native="backNextFocus('down', 2)"></el-input><!-- :disabled="item.enabled=='1'"-->
                                                <!-- <rm-pop-common datatype="seccode" kindno="REFUSEREASON" @change="hasChange" @keyup.space.native="opendialog(item.col_code,item.seqflag)" @keyup.enter.native="backNextFocus('down', 2)" @keyup.up.native="backNextFocus('up', 2)" @keyup.down.native="backNextFocus('down', 2)"></rm-pop-common> -->
                                            </span>
                                        </td>
                                    </tr>
                                    <tr v-for="(list,index) in columnData" :key="index">
                                        <td v-for="(item,sindex) in list" :key="sindex">
                                            <span class="column-item" style="width:70px" align="right" :class="item.notnull == '1' ? 'must-param' : ''">{{item.col_label}}</span>
                                            <span class="column-item" style="width:140px" v-if="item.valuetype=='2'">
                                                <el-input v-if="forminfo.hasOwnProperty(item.col_code)" v-model="masterParam[forminfo[item.col_code].field.split('$')[1]]" style="width:100%" :ref="'input'+item.seqflag" @keyup.enter.native="nextFocus(item.col_code,item.seqflag)" @input="hasChange" @dblclick.native="opendialog(item.col_code,item.seqflag)" @keyup.space.native="SpaceEvent(item.col_code,item.seqflag)" @keyup.up.native="InputMove('up',item.col_code, item.seqflag)" @keyup.down.native="InputMove('dn',item.col_code, item.seqflag)" @focus="inputFocus(item.col_code,item.seqflag)" @change="inputChangeEvent($event,item.col_code,item.seqflag)" :id="item.col_code"></el-input><!-- :disabled="item.enabled=='1'"-->
                                                <el-input v-else v-model="masterParam[item.col_code]" style="width:100%" :ref="'input'+item.seqflag" @keyup.enter.native="nextFocus(item.col_code,item.seqflag)" @input="hasChange" @dblclick.native="opendialog(item.col_code,item.seqflag)" @keyup.space.native="opendialog(item.col_code,item.seqflag)" @keyup.up.native="InputMove('up',item.col_code, item.seqflag)" @keyup.down.native="InputMove('dn',item.col_code, item.seqflag)" @focus="inputFocus(item.col_code,item.seqflag)" @change="inputChangeEvent($event,item.col_code,item.seqflag)" :id="item.col_code"></el-input><!-- :disabled="item.enabled=='1'"-->
                                            </span>
                                            <span class="column-item" style="width:130px" v-else-if="item.valuetype=='7'">
                                                <el-date-picker v-model="masterParam[item.col_code]" :inputable="true" :ref="'input'+item.seqflag" :clearable="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width:100%" @keyup.enter.native="nextFocus(item.col_code,item.seqflag)" @input="inputChangeEvent($event,item.col_code,item.seqflag)" @dblclick.native="opendialog(item.col_code,item.seqflag)" @keyup.up.native="InputMove('up', item.seqflag)" @keyup.down.native="InputMove('dn', item.seqflag)" @focus="inputFocus(item.col_code,item.seqflag)" :id="item.col_code" v-if="item.col_code=='pat_birth'" @change="inputChangeEvent($event,item.col_code,item.seqflag)"></el-date-picker>
                                                <el-date-picker v-model="masterParam[item.col_code]" :inputable="true" :ref="'input'+item.seqflag" :clearable="false" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%" @keyup.enter.native="nextFocus(item.col_code,item.seqflag)" @input="hasChange" @dblclick.native="opendialog(item.col_code,item.seqflag)" @keyup.up.native="InputMove('up', item.seqflag)" @keyup.down.native="InputMove('dn', item.seqflag)" @focus="inputFocus(item.col_code,item.seqflag)" :id="item.col_code" v-else></el-date-picker>
                                            </span>
                                        </td>
                                    </tr>
                                    <!-- <tr v-for="(list,index) in columnDataDisabled" :key="index*100+100">
                                        <td v-for="(item,sindex) in list" :key="sindex*1000+1000">
                                            <table style="width:100%;border-spacing:0.5px;" border="0">
                                                <tr>
                                                    <td style="width:70px" align="right">{{item.col_label}}</td>
                                                    <td style="width:140px" v-if="item.valuetype=='2'">
                                                        <el-input v-model="masterParam[item.col_code]" style="width:100%" :disabled="item.enabled=='0'"></el-input>
                                                    </td>
                                                    <td style="width:130px" v-else-if="item.valuetype=='7'">
                                                        <el-date-picker v-model="masterParam[item.col_code]" :clearable="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width:100%" :disabled="item.enabled=='0'">
                                                        </el-date-picker>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr> -->
                                    <tr v-for="(list,index) in columnDataChk" :key="'chklist' + index">
                                        <td v-for="(item,sindex) in list" :key="item.col_code + sindex">
                                            <span class="column-item" style="width:70px" align="right" :class="item.notnull == '1' ? 'must-param' : ''">{{item.col_label}}</span>
                                            <span class="column-item" style="width:130px">
                                                <el-checkbox v-model="masterParam[item.col_code]" true-label="1" false-label="0" @change="hasChange"></el-checkbox>
                                            </span>
                                        </td>
                                    </tr>
                                </table>
                            </el-form>
                        </div>
                        <div :style="{height: rightHeight}">
                            <div style="padding: 5px;line-height: 25px;">
                                <span style="font-size: 12px;">检索录入：</span>
                                <rm-selecttable ref="reqselect" class="req-select" :currentLable="addreqitemname" :showName="showName" :tableColumnData="allReqsheetTable" :ftableDataList="fallReqsheetList" :selplaceholder="selplaceholder" :filterColumn="filterColumn" @change="selectChange"></rm-selecttable>
                                <el-button @click="btnAddDetail(2)" class="el-button--310">分类录入</el-button>
                                <el-button @click="btnAddDetail(3)" class="el-button--310">套餐录入</el-button>
                            </div>
                            <div class="table-bottom-content" style="height: calc(100% - 37px)">
                                <vxe-table ref="rxTable" :data.sync="reqDetailList" :loading="reqDetailLoading" border height="auto" resizable show-overflow size="mini" stripe
                                    :sort-config="{trigger: 'cell'}" highlight-current-row :select-config="{reserve: true}" header-align="center" 
                                    :edit-config="{trigger: 'click', mode: 'cell', showStatus: true, showIcon: true, activeMethod: activeMethod}">
                                    <vxe-table-column field="seq" title="序号 " width="40"></vxe-table-column>
                                    <vxe-table-column field="req_itemcode" title="项目名称" width="166" :edit-render="{name:'input'}">
                                        <template v-slot:edit="{row}">
                                            <!-- <el-select ref="reqselect" popper-class="req-select" v-model="row.req_itemcode" filterable remote :remote-method="fillterRpt" @focus="clearFilter" @change="changeReqitem($event, row)" placeholder="请选择新增项目名称" style="width: 100%;">
                                                <el-option v-for="(item, i) in allReqsheetList" :key="item.req_itemcode + i" :label="item.req_itemname" :value="item.req_itemcode">
                                                    <span class="req-el-option" style="float: left;width:220px">{{ item.req_itemname }}</span>
                                                    <span style="float: right; color: #8492a6;">{{ item.req_itemcode }}</span>
                                                </el-option>
                                            </el-select> -->
                                            <rm-selecttable ref="tablereqselect" :currentLable="row.req_itemname" :showName="showName" :tableColumnData="allReqsheetTable" :ftableDataList="fallReqsheetList" :filterColumn="filterColumn" @change="changeReqitem($event, row)"></rm-selecttable>
                                        </template>
                                        <template v-slot="{row}">
                                            <span>{{getShowName(row.req_itemcode, "allReqsheetList")}}</span>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="item_price" title="价格" width="40" align="right"></vxe-table-column>
                                    <vxe-table-column field="specimen_code" title="标本类型" width="88" :edit-render="{name:'input'}">
                                        <template v-slot="{ row }">
                                            <rm-ddl-common datatype="specimen" dataname="标本类型" v-model="row.specimen_code" width="100%" key="specimen_code"></rm-ddl-common>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="qty" title="数量" width="40" align="center"></vxe-table-column>
                                    <vxe-table-column field="amount" title="金额" width="40" align="right"></vxe-table-column>
                                    <vxe-table-column field="req_groupname" title="分单类别" width="80"></vxe-table-column>
                                    <vxe-table-column field="req_itemcode" title="项目代码" width="90"></vxe-table-column>
                                    <!-- <vxe-table-column field="req_groupid" title="分单类别ID" width="119" header-align="center"></vxe-table-column> -->
                                    <template v-slot:fix>
                                        <div style="font-size:17px;padding:3px;background-color:#fff;text-align:center;font-weight:bold">
                                            <span style="position:absolute;left:10px">
                                                <el-checkbox v-model="chkSaveThenNotClearItem" true-label="1" false-label="0">保存后不清空项目</el-checkbox>
                                            </span>
                                            <el-button @click="btnAddDetail" class="el-button--310">新增明细</el-button>
                                            <el-button @click="btnDeleteDetail" class="el-button--310">删除明细</el-button>
                                            <!-- <el-button v-if="dept.length > 0" @click="saveAsSheet" class="el-button--310">存为套餐</el-button> -->
                                            <span style="color:blue;position:absolute;right:0">金额：￥{{detailAmountSum}}</span>
                                        </div>
                                    </template>
                                </vxe-table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="输入字段设置(申请录入)" :visible.sync="settingDialog" width="930px">
            <div style="height:500px">
                <rm-layout-right splitcolor="white" movingcolor="#0000ff" :splitwidth=5 :fixsize=250>
                    <template v-slot:fix>
                        <div>
                            <!-- <div style="padding-left: 10px;">
                                <el-checkbox true-label="1" false-label="0" v-model="reqLocalseting.reqinputloaclseting">输入字段本地存储</el-checkbox>
                            </div> -->
                            <div style="margin-top: 10px; text-align: center;">
                                <el-button @click.native="settingSave">确定</el-button>
                                <el-button @click.native="settingCancel">取消</el-button>
                            </div>
                        </div>
                    </template>
                    <div style="height:100%;width:100%;background-color:#ddccbb;">
                        <vxe-table ref="psetTable" :data.sync="settingData" :loading="settingloading" height="auto" border stripe 
                            highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable header-align="center" 
                            show-overflow size="mini" :edit-config="{trigger: 'click', mode: 'cell',showStatus: true,showIcon:false}" 
                            :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}">
                            <vxe-table-column field="seq_no" title="序号" width="50" :edit-render="{name:'input', autoselect: true}"></vxe-table-column>
                            <vxe-table-column field="col_name" title="字段名称" width="80"></vxe-table-column>
                            <vxe-table-column field="col_label" title="提示文字" width="80" :edit-render="{name:'input', autoselect: true}"></vxe-table-column>
                            <vxe-table-column field="default_val" title="默认值" width="70" :edit-render="{name:'input', autoselect: true}"></vxe-table-column>
                            <vxe-table-column field="visibled" title="可见" width="40" align="center">
                                <template v-slot="{row}">
                                    <el-checkbox v-model="row.visibled" true-label="1" false-label="0"></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="enabled" title="可编辑" width="50" align="center">
                                <template v-slot="{row}">
                                    <el-checkbox v-model="row.enabled" true-label="1" false-label="0"></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="notnull" title="必填" width="40" align="center">
                                <template v-slot="{row}">
                                    <el-checkbox v-model="row.notnull" true-label="1" false-label="0"></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="noedit" title="禁止双击" width="70" align="center">
                                <template v-slot="{row}">
                                    <el-checkbox v-model="row.noedit" true-label="1" false-label="0"></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="rem_last" title="自动记忆" width="70" align="center">
                                <template v-slot="{row}">
                                    <el-checkbox v-model="row.rem_last" true-label="1" false-label="0"></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="col_code" title="字体代码" width="89"></vxe-table-column>
                        </vxe-table>
                    </div>
                </rm-layout-right>
            </div>
        </el-dialog>
        <!--双击弹窗-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="dialogtitle" v-if="dialogform" :visible.sync="dialogform">
            <rm-pop-common @change="popComChange" @cancel="dialogform=false" :datatype="datatype" :kindno="kindno"></rm-pop-common>
        </el-dialog>
        <!--申请项目双击弹窗-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择申请项目" v-if="dialogReqItem" :visible.sync="dialogReqItem" width="930px" @closed="closeReqitem(1, 'rmreqitem')">
            <div>
                <rm-ReqItem-new ref="rmreqitem" @change="reqitemchange" @cancel="dialogReqItem=false;" :showGroup="true" :multiChk="true"></rm-ReqItem-new>
            </div>
            <!-- <rm-ReqItem-new @change="reqitemchange" @cancel="dialogReqItem=false;" :showGroup="true" :multiChk="true"></rm-ReqItem-new> -->
        </el-dialog>
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择申请项目" :visible.sync="dialogReqItem1" v-if="dialogReqItem1" width="910px">
            <rm-reqsheet prono="LIS254" @change="chooseReqsheet"></rm-reqsheet>
        </el-dialog>
    </div>
</template>

<script>
import reqitem from '@/components/common/reqitem';
import XEUtils from "xe-utils"; //引入工具类
import RmSelecttable from "@/components/rmcompents/rm_selecttable.vue";
import RmReqsheet from "@/components/rmcompents/rmreq/rm_reqsheet.vue";
export default {
    name: "LIS254",
    components: {
        RmSelecttable,
        RmReqsheet
    },
    data() {
        return {
            searchParam: {
                startdt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                txtcreateuser: "",
            },
            actionindex: "M",
            changeflag: false,
            reqMasterList: [],
            reqMasterLoading: false,
            settingDialog: false,
            settingData: [],
            settingloading: false,
            chkSupportMutiplePrint: "1",
            selectRow: {},
            formheight: 0,
            rightHeight: 0,
            // haveUpt: false,
            nodata: true,
            reqBack: {
                barcode: "",
                reject_reason: "",
            },
            masterParam: {
                pat_agestr: "",
                pat_birth: ""
            },
            columnData: [],
            columnDataDisabled: [],
            columnDataChk: [],
            reqDetailList: [],
            reqDetailLoading: false,
            chkSaveThenNotClearItem: "0", //保存后不清空项目
            initHosp: {
                pat_hospcode: "",
                pat_hospname: ""
            },
            barcodestyle: "",
            cxbarcodeprinter: "",
            //DDL快速输入码
            InputCodeArr: [],
            forminfo: reqitem.forminfo,
            defaultCol: reqitem.defaultCol,
            allReqsheetTable: reqitem.allReqsheetTable,
            filterColumn: reqitem.filterColumn,
            showName: reqitem.showName,
            selplaceholder: reqitem.selplaceholder,
            allReqsheetList: [],
            fallReqsheetList: [],
            allReqsheetListMap: [],
            addreqitemname: "",
            dialogtitle: "",
            dialogform: false,
            dialogReqItem: false,
            dialogReqItem1: false,
        }
    },
    computed: {
        detailAmountSum() {
            return XEUtils.sum(this.reqDetailList, "amount");
        },
        detailseq() {
            let data = this.$refs.rxTable.tableData;
            if (data.length > 0) {
                return (data.length + 1) * 10;
            } else {
                return 10;
            }
        }
    },
    mounted() {
        this.searchParam.txtcreateuser = this.$tool.getSession(this.$tool.loginuserno);
        this.initData(); //初始化下拉框的数据
        this.queryDdl();
    },
    methods: {
        initData() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "initdata"
                    }
                })
                .then(res => {
                    this.settingData = res.columnData;
                    this.initHosp.pat_hospcode = res.hospcode;
                    this.initHosp.pat_hospname = res.hospname;
                    this.barcodestyle = res.barcodestyle;
                    this.cxbarcodeprinter = res.cxbarcodeprinter;
                    //this.columnData = res.columnData;
                    this.initColumn();
                    // this.rcvliststyleid = res.rcvliststyleid;
                    // this.reqliststyleid = res.reqliststyleid;
                    this.dept = res.dept;
                    // this.fhaveUpt = res.haveUpt;
                    // this.haveUpt = this.fhaveUpt;
                    this.IsAreaMode = res.IsAreaMode;
                    // this.fallReqsheetList = XEUtils.clone(res.Reqitem2.data, true);
                    this.allReqsheetList = res.Reqitem2.data;
                    this.allReqsheetListMap = this.$pub.arrayToMap(this.allReqsheetList, "req_itemcode", "req_itemname");
                    this.queryReqsheet();
                })
                .catch(err => {});
        },
        queryReqsheet() {
            var that = this;
            that.$tool
                .request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "queryreqsheet"
                    }
                })
                .then(res => {
                    if (res.errcode == "1") {
                        res.reqsheet.forEach(element => {
                            that.allReqsheetList.push({
                                req_itemname: "套餐：" + element.sheet_name,
                                req_itemcode: element.req_sheetid.toString(),
                                inputcode: element.inputcode ? element.inputcode : "",
                                tc: "tc"
                            });
                        });
                        that.fallReqsheetList = XEUtils.clone(that.allReqsheetList, true);
                    }
                })
                .catch(e => {
                    console.log("error", e);
                });
        },
        // 查询申请_开单套餐_项目
        queryReqsheetitems(reqsheetid, type) {
            var that = this;
            that.$tool
                .request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "queryreqsheetitem",
                        req_sheetid: reqsheetid
                    }
                })
                .then(response => {
                    if (type == 1) {
                        // 新增项目，插入套餐项目
                        if (response.details.length > 0) {
                            that.reqitemchange(response.details);
                            that.changeflag = true;
                        }
                    }
                })
                .catch(e => {});
        },
        queryDdl() {
            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            //初始化获取所有的InputCodeArr
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "queryddl",
                    }
                })
                .then(res => {
                    var inputCodeArr = res.inputCodeArr;
                    var sale = inputCodeArr.find(item => item.key == "sampled_user$sampled_username");
                    if (sale) {
                        inputCodeArr.push({ key: "saleman$saleman", list: sale.list });
                    }
                    this.InputCodeArr = inputCodeArr;
                    loading.close();
                });
        },
        initColumn() {
            var that = this;
            //取出所有可见可編輯的数据
            let data = that.settingData.filter(item => item.visibled == "1" && item.enabled == "1");
            //取出所有可见不可編輯的数据
            let disdata = that.settingData.filter(item => item.visibled == "1" && item.enabled != "1");
            this.defaultCol.forEach(item => {
                // let tempdata = that.columnClass(item.name, item.code, item.type);
                let tempdata = { "col_code": item.code, "col_label": item.name, "col_name": item.name, "default_val": "", "enabled": "0", "noedit": "", "prg_no": "LIS254", "rem_last": "0", "reserved": "", "seq_no": 10, "valuelist": "", "valuetype": item.type, "visibled": "1" };
                disdata.push(tempdata);
            });
            //取出可见所有checkbox的数据
            let chkdata = [];
            let chkdata1 = data.filter(item => item.valuetype == "1");
            data = data.filter(item => item.valuetype != "1");
            let chkdata2 = disdata.filter(item => item.valuetype == "1");
            disdata = disdata.filter(item => item.valuetype != "1");
            chkdata = XEUtils.union(chkdata1, chkdata2);
            //计算行数
            let len = data.length;
            let rows = Math.ceil(len / 3);
            data.forEach((item, index) => {
                item.seqflag = index + 1;
            });
            //计算高度
            // this.formheight = 23 * (rows + Math.ceil(disdata.length / 3) + Math.ceil(chkdata.length / 3));
            that.formheight = 23 * (1 + rows + Math.ceil(chkdata.length / 3));
            that.rightHeight = "calc(100% - " + that.formheight + "px)";
            that.formkey++;
            //焦点定位赋值
            let ys = len % 3;
            let column1 = 1;
            let column2 = rows + 1;
            let column3 = len % 3 == 1 ? rows * 2 : rows * 2 + 1;
            let columnarr = [column1, column2, column3];
            let disarraycol = XEUtils.chunk(disdata, 3);
            this.columnDataDisabled = disarraycol;
            //带有checkbox在目前只有两个，暂时先这样
            let chkarraycol = XEUtils.chunk(chkdata, 3);
            that.columnDataChk = chkarraycol;

            let arraycol = XEUtils.chunk(data, 3);
            that.columnData = arraycol;
            for (let i = 0; i < arraycol.length; i++) {
                for (let j = 0; j < arraycol[i].length; j ++) {
                    arraycol[i][j].seqflag = columnarr[j];
                    columnarr[j]++;
                }
            }
        },
        // columnClass(name, code, type) {
        //     console.log(name, code, type)
        //     let data = { "col_code": code, "col_label": name, "col_name": name, "default_val": "", "enabled": "0", "noedit": "", "prg_no": "LIS254", "rem_last": "0", "reserved": "", "seq_no": 10, "valuelist": "", "valuetype": type, "visibled": "1" };
        //     console(data)
        //     return data;
        // },
        queryList() {
            console.log(this.searchParam)
            this.reqMasterLoading = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "queryreqmaster",
                        //这些条件暂时不用
                        // ChkSaveThenPrintLabel: this.ChkSaveThenPrintLabel,
                        // ChkAutoAssignLabelQty: this.ChkAutoAssignLabelQty,
                        // ChkReqitemAutoemory: this.ChkReqitemAutoemory,
                        // ChkNoShowReqBarcode: this.ChkNoShowReqBarcode,
                        // ChkNoShowPatnoThenCreateBarcode: this.ChkNoShowReqBarcode,
                        // ChkSupportMutiplePrint: this.ChkSupportMutiplePrint,
                        ...this.searchParam
                    }
                })
                .then(res => {
                    this.reqMasterList = res.data;
                    this.reqMasterLoading = false;
                    this.clearRightData();
                    if (res.data.length == 0) {
                        this.$refs.lxTable.clearCurrentRow();
                    }
                })
                .catch(err => {
                    this.$alert(err, "提示");
                    this.reqMasterLoading = false;
                });
        },
        MainOpenDialog(type) {
            switch (type) {
                case 1:
                    this.btnAdd();
                    break;
                case 2:
                    this.btnDelete();
                    break;
                case 3:
                    this.btnSave();
                    break;
                case 4:
                    this.btnCancel();
                    break;
            }
        },
        btnAdd() {
            this.changeflag = true;
            // this.haveUpt = true;
            this.actionindex = "A";
            this.nodata = false;
            this.reqBack = {};
            this.masterParam = {
                pat_hospcode: XEUtils.clone(this.initHosp.pat_hospcode, true),
                pat_hospname: XEUtils.clone(this.initHosp.pat_hospname, true),
                charge_flag: "0",
                req_deptno: "",
                req_dt: "",
                pat_typecode: "",
                req_docno: "",
                original_reqno: "",
                pat_no: "",
                req_wardno: "",
                sampled_user: "",
                pat_name: "",
                req_bedno: "",
                sampled_dt: "",
                pat_sex: "1",
                pat_sexname: "男",
                pat_address: "",
                perform_dept: "",
                pat_agestr: "",
                pat_birth: "",
                saleman: "",
                pat_diag: "",
                pat_phone: "",
                barcode: "",
                req_comm: "",
                specimen_code: "",
                pat_idcardno: "",
                emer_flag: "0"
            };
            this.selectRow = {};
            for (let i = 0; i < this.columnData.length; i++) {
                for (let j = 0; j < this.columnData[i].length; j++) {
                    let col = this.columnData[i][j];
                    let colinfo = col.col_code;
                    let value = col.default_val;
                    if (col.default_val != "" && col.col_code != "pat_hospcode") {
                        var list = this.InputCodeArr.filter(item => item.key.indexOf(colinfo) > -1);
                        if (list.length > 0) {
                            var row = list[0].list.Data.filter(item => (item.inputcode + "").toUpperCase() == (value + "").toUpperCase() || (item.hidkey + "").toUpperCase() == (value + "").toUpperCase());
                            if (row.length > 0) {
                                this.masterParam[this.forminfo[colinfo].field.split("$")[1]] = row[0].hidname;
                                this.masterParam[colinfo] = row[0].hidkey;
                            } else {
                                if (colinfo == "pat_sex" || colinfo == "pat_typecode" || colinfo == "specimen_code") {
                                    this.opendialog(colinfo, refinfo);
                                } else {
                                    var re = new RegExp("[\\u4e00-\\u9fa5]", "gi");
                                    if (!re.test(value)) {
                                        this.opendialog(colinfo, refinfo);
                                    }
                                }
                            }
                        } else {
                            this.masterParam[col.col_code] = col.default_val;
                        }
                    }
                }
            }
            this.addrxTable();
            setTimeout(() => {
                // let focusitem = this.columnData[0][0].col_code;
                // console.log(focusitem);
                // document.getElementById(focusitem).focus();
                this.$refs.barcode.focus();
            }, 100);
            this.addreqitemname = "";
        },
        addrxTable(type) {
            if (this.ChkSaveThenNotClearItem == "0") {
                // 勾选保存后清空项目
                this.detail = [];
                //this.detail.push({ seq: this.detailseq, qty: "1" });
            }
            if (type != 1) {
                return false;
            }
            setTimeout(() => {
                if (this.ChkSaveThenNotClearItem != "1") {
                    this.$refs.rxTable.insertAt({ seq: this.detailseq, qty: "1" }, -1);
                }
            }, 100);
        },
        btnDelete() {
            var delrow = this.$refs.lxTable.getCurrentRow();
            if (delrow) {
                this.$confirm("确定删除条码号：<span style='color:red;'>" + delrow.barcode + "</span> 的无效申请单吗？", '提示', {
                    dangerouslyUseHTMLString: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var alld = this.$refs.lxTable.tableData;
                    var rowindex = alld.indexOf(delrow);
                    this.$refs.lxTable.remove(delrow);
                    this.actionindex = "D";
                    this.masterParam = delrow;
                    this.save().then(res => {
                        if (res.errcode == "1") {
                            let havedata = this.$refs.lxTable.tableData;
                            console.log(havedata)
                            if (havedata.length > 0) {
                                if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                                this.selectrow = havedata[rowindex];
                                this.highLightRow(this.selectrow);
                            } else {
                                this.highLightRow();
                            }
                            this.actionindex = "M";
                            this.$pub.message(this, "删除成功！", "success");
                        } else {
                            this.$pub.message(this, "删除失败！" + res.errmsg, "error");
                        }
                    });
                }).catch(() => { });
            }
        }, 
        btnSave() {
            console.log(this.reqBack)
            if (!this.reqBack.barcode) {
                this.$pub.message(this, "条码号不能为空！", "warning");
                return false;
            }
            if (!this.reqBack.reject_reason) {
                this.$pub.message(this, "退回原因不能为空！", "warning");
                return false;
            }
            if (this.actionindex == "A") {
                this.exesave();
            } else if (this.actionindex == "M") {
                //数据修改
                this.$confirm("确定要修改此申请单吗？", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.exesave();
                })
                .catch(() => {
                    this.$confirm("你确定要取消这次改动？", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    }).then(() => {
                        this.getReqDetails();
                    })
                    .catch(() => {
                        this.exesave();
                    });
                });
            }
        },
        async exesave() {
            this.save().then(res => {
                if (res.errcode == "1") {
                    this.$pub.message(this, "保存成功！", "success");
                    this.actionindex = "M";
                    if (this.ChkSaveThenPrintLabel == "1") {
                        this.$pub.printbarcode(this, res.keyid, "1", this.barcodestyle, this.cxbarcodeprinter, "1");
                    }
                    this.queryList(res.keyid);
                    this.changeflag = false;
                    this.addreqitemname = "";
                    // this.allReqsheetList = XEUtils.clone(this.fallReqsheetList, true);
                    // this.filterreqlist();
                    // this.btnAdd();
                } else {
                    this.$pub.message(this, "保存失败！" + res.errmsg, "error");
                }
            });
        }, //form保存
        async save() {
            this.saveBeforeVerify();
            var param = {
                ...this.masterParam
            };
            param.barcode = this.reqBack.barcode;
            param.reject_reason = this.reqBack.reject_reason;
            console.log(param)
            const result = await this.$tool.request({
                url: "LIS/LIS2/LIS254",
                method: "post",
                data: {
                    action: "saverecord",
                    actionindex: this.actionindex,
                    saveinfo: param,
                    oldinfo: this.oldmasterList,
                    urec: this.$refs.rxTable.tableData,
                    ChkSaveThenNotClearItem: this.ChkSaveThenNotClearItem
                }
            });
            return result;
        }, //保存前做一下校验
        saveBeforeVerify() {
            let data = this.$refs.rxTable.tableData;
            //写入分单类别
            if (data.length > 0) {
                this.masterParam.req_groupid = data[0].req_groupid;
                this.masterParam.req_groupna = data[0].req_groupna;
            }
            //写入申请项目简称
            if (data.length > 0) {
                let req_itemnas = "";
                data.forEach(item => {
                    if (req_itemnas == "") {
                        req_itemnas = !!item.req_itemna ? item.req_itemna : item.req_itemname;
                    } else {
                        req_itemnas = req_itemnas + "," + (!!item.req_itemna ? item.req_itemna : item.req_itemname);
                    }
                });
                this.masterParam.sample_items = req_itemnas;
            }
        },
        btnCancel() {
            this.$confirm("您确定要取消这次改动吗？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                if (this.selectRow.barcode) {
                    this.getReqDetails(this.selectRow);
                } else {
                    this.clearRightData();
                }
                this.changeflag = false;
                // if( this.$refs.lxTable.)
                this.judgeChangeUpt();
                // this.haveUpt = this.fhaveUpt;
                this.addreqitemname = "";
            })
            .catch(() => {});
        },
        judgeChangeUpt() {
            let userno = this.$tool.getSession(this.$tool.loginuserno);
            if (this.selectRow.barcode && this.selectRow.create_user == userno) {
                this.nodata = false;
            } else {
                this.nodata = true;
            }
        },
        btnPrint() {
            if (this.barcodestyle != "") {
                let barcodestr = "";
                let data = this.$refs.lxTable.getSelectRecords();
                if (data.length > 0) {
                    const rLoading = this.$pub.openLoading(this, "正在打印条码……");
                    data.forEach(item => {
                        if (barcodestr == "") {
                            barcodestr = item.barcode;
                        } else {
                            barcodestr = barcodestr + "," + item.barcode;
                        }
                    });
                    this.$pub.printbarcode(this, barcodestr, "1", this.barcodestyle, this.cxbarcodeprinter, "1");
                    rLoading.close();
                } else {
                    this.$alert("请勾选需要打印的数据！", "提示");
                }
            } else {
                this.$alert("没有设置条码的打印样式", "错误", {
                    confirmButtonText: "确定"
                });
            }
        },
        btnSet() {
            this.settingDialog = true;
        },
        settingSave() {
            let xtabledata = this.$refs.psetTable.tableData;
            xtabledata.sort((a, b) => {
                return a.seq_no - b.seq_no;
            });
            for (let i = 0, len = xtabledata.length; i < len; i++) {
                xtabledata[i].seq_no = (i + 1) * 10;
            }
            this.$tool.request({
                url: "LIS/LIS2/LIS254",
                method: "post",
                data: {
                    action: "inputcolsave",
                    urec: this.$refs.psetTable.getRecordset(),
                }
            }).then(res => {
                if (res.errcode == "1") {
                    this.$pub.message(this, "保存成功", "success");
                    this.initData();
                    this.settingDialog = false;
                } else {
                    this.$pub.message(this, "保存失败" + res.errmsg, "error");
                }
            })
        },
        settingCancel() {
            this.settingDialog = false;
        },
        currentChangeEvent({ row }) {
            this.nodata = false;
            if (!this.changeflag) {
                this.selectRow = row;
                this.getReqDetails(row);
            } else {
                this.$refs.lxTable.setCurrentRow(this.selectRow);
            }
        },
        getReqDetails(row) {
            if (row) {
                this.selectRow = row;
                this.actionindex = "M";
                this.$tool.request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "getdetails",
                        barcode: row.barcode
                    }
                })
                .then((res) => {
                    if (res.master.length > 0) {
                        this.reqBack.barcode = res.master[0].barcode;
                        this.reqBack.reject_reason = res.master[0].reject_reason;
                        this.masterParam = res.master[0];
                        this.oldmasterList = XEUtils.clone(res.master[0], true);
                        this.reqDetailList = res.detail;
                        if (res.detail.length > 0) {
                            this.$refs.rxTable.setCurrentRow(res.detail[0]);
                        } else {
                            this.$refs.rxTable.setCurrentRow(null);
                        }
                    } else {
                        this.clearRightData();
                    }
                    this.judgeChangeUpt();
                })
                .catch((e) => {
                    this.$message.error(e);
                });
            } else {
                this.highLightRow();
            }
        },
        highLightRow(row) {
            if (row) {
                this.$refs.lxTable.setCurrentRow(row);
                this.getReqDetails(row);
                this.nodata = false;
            } else {
                this.$refs.lxTable.clearCurrentRow();
                // this.master = [];
                this.clearRightData();
                // this.haveUpt = false;
            }
        },
        rowClassName({ row }) {
            return this.$pub.getreqstatclass(row.req_stat);
        },
        activeMethod({ row, column }) {
            if (column.property == "req_itemcode" && !this.nodata) {
                return true;
            } 
        },
        closeReqitem(type, ref) {
            if (type == 1) {
                // 组件
                this.$refs[ref].$refs.xTable.clearSelection();
            } else {
                this.$refs[ref].clearSelection();
            }
        },
        getShowName(code, list, row) {
            if (row) {
                row.req_itemname = this[list + "Map"].get(code);
            }
            return this[list + "Map"].get(code);
        },
        btnAddDetail(type, e) {
            console.log(type, e);
            if (this.nodata) {
                //如果没有数据禁止添加明细，得先点击新增
                // this.addreqitemname = "";
                // this.allReqsheetList = XEUtils.clone(this.fallReqsheetList, true);
                // this.filterreqlist();
                return false;
            } else {
                if (type == 1 && e) {
                    let req = this.fallReqsheetList.find(item => item.req_itemcode == e);
                    console.log(req)
                    if (req) {
                        if (req.hasOwnProperty("tc")) {
                            console.log("套餐");
                            this.queryReqsheetitems(e, 1);
                        } else {
                            let arr = [
                                {
                                    seq: this.detailseq,
                                    qty: 1,
                                    req_itemcode: req.req_itemcode,
                                    req_itemname: req.req_itemname,
                                    item_price: req.item_price,
                                    amount: req.item_price,
                                    specimen_code: req.specimen_code,
                                    req_groupname: req.req_groupname
                                }
                            ];
                            this.reqitemchange(arr);
                            this.changeflag = true;
                        }
                        // this.filterreqlist();
                    }
                } else if (type == 2) {
                    // 分类弹窗
                    this.dialogReqItem = true;
                } else if (type == 3) {
                    // 套餐弹窗
                    this.dialogReqItem1 = true;
                } else {
                    let arr = {
                        seq: this.detailseq,
                        qty: 1,
                    };
                    this.$refs.rxTable.insert(arr).then(rows => {
                        this.$refs.rxTable.setCurrentRow(rows.row);
                        this.$refs.rxTable.setActiveCell(rows.row, "req_itemcode");
                    });
                    this.changeflag = true;
                }
            }
        },
        btnDeleteDetail() {
            if (this.nodata) {
                return false;
            } else {
                var delrow = this.$refs.rxTable.getCurrentRow();
                if (delrow) {
                    var alld = this.$refs.rxTable.tableData;
                    var rowindex = alld.indexOf(delrow);
                    this.$refs.rxTable.remove(delrow);
                    let havedata = this.$refs.rxTable.tableData;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        let selectrow = havedata[rowindex];
                        this.$refs.rxTable.setCurrentRow(selectrow);
                        this.changeflag = true;
                    }
                }
            }
        },
        selectChange(row) {
            console.log(row)
            if (row) {
                this.addreqitemname = row.req_itemname;
                this.btnAddDetail(1, row.req_itemcode);
            } else {
                this.addreqitemname = "";
            }
        },
        opendialog(colinfo, refinfo) {
            if (colinfo == 'refusereason') {
                this.dialogtitle = "双击或空格键弹出退回原因";
                this.datatype = "seccode";
                this.kindno = "REFUSEREASON";
                this.field = "seccode$REFUSEREASON$" + "input" + refinfo;
            } else {
                let info = this.forminfo[colinfo];
                console.log(this.forminfo, info)
                if (!info) return false;
                let action = info.action.split("$");
                // let field = info.field.split("$");
                this.dialogtitle = info.title;
                this.datatype = action[0];
                this.kindno = action[1];
                this.field = info.field + "$" + "input" + refinfo;
            }
            this.dialogform = true;
        },
        async inputChangeEvent(value, colinfo, refinfo) {
            switch (colinfo) {
                case "pat_agestr":
                    this.masterParam.pat_birth = "";//清空生日
                    var reg = new RegExp("\\d{1,}(y|Y|岁|年){0,}\\d{0,}(m|M|月){0,}\\d{0,}(d|D|日){0,}\\d{0,}(h|H|小时){0,}\\d{0,}(f|F|分钟){0,}", "gi");
                    var regd = new RegExp("^\\d{1,}$", "gi");
                    var regda = new RegExp("\\d{1,}", "gi");
                    if (value.match(regd)) {
                        this.masterList[colinfo] = value + "岁";
                        this.masterList["pat_ageyear"] = value - 0;
                    } else if (value.match(reg)) {
                        this.masterList[colinfo] =
                            value
                                .replace("y", "岁")
                                .replace("年", "岁")
                                .replace("Y", "岁")
                                .replace("m", "月")
                                .replace("M", "月")
                                .replace("d", "日")
                                .replace("D", "日")
                                .replace("h", "小时")
                                .replace("H", "小时")
                                .replace("f", "分钟")
                                .replace("F", "分钟") + "";
                        this.masterList.pat_ageyear = this.$pub.ageTransform(this.masterList.pat_agestr);
                    } else {
                        this.$confirm("无效的病人年龄!", "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            focusCancelButton: false,
                            closeOnClickModal: false,
                            type: "warning"
                        })
                            .then(() => {})
                            .catch(() => {});
                    }
                    break;
                case "pat_birth":
                    const result = await this.computedAgeORbirth(colinfo, value);
                    // if (colinfo == "pat_agestr") {
                    //     this.masterParam.pat_agestr = value;
                    //     this.masterParam.pat_ageyear = result.Item1;
                    //     this.masterParam.pat_birth = result.Item2;
                    // } else {
                        this.masterParam.pat_agestr = result;
                        this.$forceUpdate();
                    // }
                    this.hasChange();
                    break;
                case "pat_idcardno":
                    this.calcBirthAgeSex(value);
                    break;
                default:
                    if (value.trim()) {
                        var list = this.InputCodeArr.filter(item => item.key.indexOf(colinfo) > -1);
                        if (list.length > 0) {
                            var row = list[0].list.Data.filter(item => (item.inputcode + "").toUpperCase() == (value + "").toUpperCase() || (item.hidkey + "").toUpperCase() == (value + "").toUpperCase());
                            if (row.length > 0) {
                                this.masterParam[this.forminfo[colinfo].field.split("$")[1]] = row[0].hidname;
                                this.masterParam[colinfo] = row[0].hidkey;
                            } else {
                                if (colinfo == "pat_sex" || colinfo == "pat_typecode" || colinfo == "specimen_code") {
                                    this.opendialog(colinfo, refinfo);
                                } else {
                                    var re = new RegExp("[\\u4e00-\\u9fa5]", "gi");
                                    if (!re.test(value)) {
                                        this.opendialog(colinfo, refinfo);
                                    }
                                }
                            }
                        }
                    } else {
                        this.masterParam[this.forminfo[colinfo].field.split("$")[1]] = "";
                        this.masterParam[colinfo] = "";
                    }
                    break;
            }
        },
        async computedAgeORbirth(colinfo, value) {
            try {
                const result = await this.$tool.request({
                    url: "LIS/LIS2/LIS254",
                    method: "post",
                    data: {
                        action: "patageOrpatbirth",
                        mod: colinfo,
                        value: value
                    }
                });
                return result;
            } catch (e) {
                this.$alert(e, "出错");
            }
        },
        calcBirthAgeSex(pat_idcardno) {
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if (!pat_idcardno) return false;
            if (reg.test(pat_idcardno)) {
                if ( parseInt(pat_idcardno.substr(16,1)) % 2 == 1) { // 获取性别
                    this.masterParam.pat_sex = "1";
                    this.masterParam.pat_sexname = "男";
                } else {
                    this.masterParam.pat_sex = "2";
                    this.masterParam.pat_sexname = "女";
                }
                // 获取出生日期
                this.masterParam.pat_birth = pat_idcardno.substring(6,10) + "-" + pat_idcardno.substring(10,12) + "-" + pat_idcardno.substring(12,14);
                let yearBirth = pat_idcardno.substring(6,10)
                let monthBirth = pat_idcardno.substring(10,12);
                let dayBirth = pat_idcardno.substring(12,14);
                // 获取当前年月日并计算年龄
                let myDate = new Date();
                let monthNow = myDate.getMonth() + 1;
                let dayNow = myDate.getDate();
                let age = myDate.getFullYear() - yearBirth;
                if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
                    age --;
                }
                // 得到年龄
                this.masterParam.pat_agestr = age;
            } else {
                this.$alert("请输入有效身份证号码！", "提示");
            }
        },
        SpaceEvent(colinfo, refinfo) {
            var val = this.masterParam[this.forminfo[colinfo].field.split("$")[1]];
            if (!val.replace(/\s*/g, "")) {
                this.opendialog(colinfo, refinfo);
            }
        },
        popComChange(code, name) {
            console.log(code, name)
            console.log(this.field)
            let field = this.field.split("$");
            if (field[1] == 'REFUSEREASON') {
                this.reqBack.reject_reason = name;
                this.$refs.inputbackreason.focus();
            } else {
                this.masterParam[field[0]] = code;
                this.masterParam[field[1]] = name;
                this.$refs[field[2]][0].focus();
                this.$refs[field[2]][0].select();
                console.log(this.masterParam)
            }
            this.dialogform = false;
            this.hasChange();
        },
        hasChange() {
            this.changeflag = true;
        },
        backNextFocus(type, index) {
            if (type == 'down') {
                if (index == 1) {
                    this.$refs.inputbackreason.focus();
                } else if (index == 2) {
                    setTimeout(() => {
                        let focusitem = this.columnData[0][0].col_code;
                        console.log(focusitem);
                        document.getElementById(focusitem).focus();
                    }, 100);
                }
            } else {
                this.$refs.barcode.focus();
            }
        },
        //申请项目数据回传
        reqitemchange(code, name, row) {
            var rptlist = this.$refs.rxTable.getTableData().fullData;
            var data3 = XEUtils.clone(rptlist, true);
            if (code && code.length > 0) {
                console.log(code, name, row);
                for (let i = 0; i < code.length; i++) {
                    var rpt = code[i];
                    console.log(rpt, rpt.req_itemcode)
                    var data = data3.find(m => m.req_itemcode == rpt.req_itemcode);
                    console.log(data)
                    if (!data) {
                    // if (!data.req_itemcode) {
                        if (i == code.length - 1) {
                            this.$refs.rxTable.insert({ req_itemname: rpt.req_itemname, req_itemcode: rpt.req_itemcode, item_price: rpt.item_price, amount: rpt.amount, specimen_code: rpt.specimen_code, req_groupname: code[i].req_groupname, req_groupid: rpt.req_groupid, seq: this.detailseq, qty: 1 }).then(rows => {
                                this.$refs.rxTable.setCurrentRow(rows.row);
                                // this.$refs.rxTable.setActiveCell(rows.row, "req_itemcode");
                            });
                        } else {
                            this.$refs.rxTable.insert({ req_itemname: rpt.req_itemname, req_itemcode: rpt.req_itemcode, item_price: rpt.item_price, amount: rpt.amount, specimen_code: rpt.specimen_code, req_groupname: code[i].req_groupname, req_groupid: rpt.req_groupid, seq: this.detailseq, qty: 1 });
                        }
                    }
                    // } else {
                    //     // this.$refs.rxTable.insert({ seq: this.detailseq, qty: 1 }).then(rows => {
                    //     //     this.$refs.rxTable.setCurrentRow(rows.row);
                    //     //     this.$refs.rxTable.setActiveCell(rows.row, "req_itemcode");
                    //     // });
                    //     var nowrow = this.$refs.rxTable.getCurrentRow();
                    //     nowrow.req_itemcode = "";
                    // }
                }
            }
            this.changeflag = true;
            this.dialogReqItem = false;
            this.dialogReqItem1 = false;
        },
        // 回车切换输入框
        nextFocus(colcode, index) {
            if (index > 26) return false;
            var that = this;
            var focusIndex = index + 1;
            setTimeout(function() {
                // if (index == 5) {
                //     that.$refs["input" + index][0].blur();
                // }
                //if (index == 24 || index == 25) {
                //checkbox
                //  that.$refs["input" + focusIndex][0].$el.focus();
                //}
                // else if (index == 7 || index == 17 || index == 18) {
                //date
                //  that.$refs["input" + focusIndex][0].focus();
                // } else {
                //input
                //  that.$refs["input" + focusIndex][0].focus();
                //}
                if (that.$refs["input" + focusIndex]) {
                    that.$refs["input" + focusIndex][0].focus();
                    if (["_dt", "_date"].indexOf(that.$refs["input" + focusIndex][0].id) == -1) {
                        //  that.HightlightPos(that.$refs["input" + focusIndex][0].value, colcode, index);
                    } else {
                        that.$refs["input" + focusIndex][0].select();
                    }
                } else {
                    that.$refs.reqselect.$refs.tableSelect.focus();
                }
            }, 1);
            //this.InputMove("dn",index);
        },
        inputFocus(colcode, index) {
            // let that = this;
            //that.$refs["input" + index][0].select();
            //console.log("GSGAH", that.$refs["input" + index]);
            this.hightlightPos(this.$refs["input" + index][0].value, colcode, index);
        },
        changeReqitem(selectrow, row) {
            if (!selectrow) {
                row.req_itemcode = "";
                row.req_itemname = "";
                row.specimen_code = "";
                row.req_groupname = "";
                row.qty = "";
                row.item_price = "";
                row.amount = "";
                return false;
            }
            var e = selectrow.req_itemcode;
            console.log(selectrow, e, row)
            let req = this.fallReqsheetList.find(item => item.req_itemcode == e);
            // console.log(req)
            if (req) {
                if (req.hasOwnProperty("tc")) {
                    console.log("套餐");
                    this.queryReqsheetitems(e, 1);
                } else {
                    let rpt = {
                            seq: this.detailseq,
                            qty: 1,
                            req_itemcode: e,
                            specimen_code: selectrow.specimen_code
                            // req_itemname: req.req_itemname
                        }
                    ;
                    // this.reqitemchange(arr);
                    var rptlist = this.$refs.rxTable.getTableData().fullData;
                    console.log(rptlist)
                    var data3 = XEUtils.clone(rptlist, true);
                    var data = data3.filter(m => m.req_itemcode == rpt.req_itemcode);
                    console.log(data, row.req_itemcode)
                    if (!row.req_itemcode) {
                        if (data.length < 1) {
                        //     this.$refs.rxTable.insert({ req_itemname: rpt.req_itemname, req_itemcode: rpt.req_itemcode, item_price: rpt.item_price, amount: rpt.amount, specimen_name: rpt.specimen_name, req_groupname: rpt.req_groupname, req_groupid: rpt.req_groupid, seq: this.detailseq, qty: rpt.qty });
                        // } else if (data.length == 1) {
                            row.req_itemcode = rpt.req_itemcode;
                            var selectrow = this.allReqsheetList.find(t => t.req_itemcode == rpt.req_itemcode);
                            if (selectrow) {
                                row.specimen_code = selectrow.specimen_code;
                                row.req_groupname = selectrow.req_groupname;
                                row.item_price = selectrow.item_price;
                                row.amount = selectrow.item_price * row.qty;
                            }
                            this.$refs.rxTable.insert({ seq: this.detailseq, qty: 1 }).then(rows => {
                                this.$refs.rxTable.setCurrentRow(rows.row);
                                this.$refs.rxTable.setActiveCell(rows.row, "req_itemcode");
                            });
                        } else {
                            row.req_itemcode = "";
                            row.req_itemname = "";
                            row.specimen_code = "";
                            row.req_groupname = "";
                            row.item_price = "";
                            row.amount = "";
                        }
                    } else {
                        row.req_itemcode = e;
                        row.req_itemname = selectrow.req_itemname;
                        row.specimen_code = selectrow.specimen_code;
                        row.req_groupname = selectrow.req_groupname;
                        row.item_price = selectrow.item_price;
                        row.amount = selectrow.item_price;
                        this.$refs.rxTable.clearActived();
                    }
                    this.changeflag = true;
                }
                // this.filterreqlist();
            }
        },
        hightlightPos(myValue, colcode, index) {
            if (!myValue) myValue = "";
            try {
                var myField = {};
                if (colcode.toUpperCase().indexOf("_DT") == -1 || colcode.toUpperCase().indexOf("_DATE") == -1 || colcode == "pat_birth") {
                    myField = this.$refs["input" + index][0].$refs.reference.$refs.input;
                } else {
                    myField = this.$refs["input" + index][0].$refs.input;
                }
                if (myField.selectionStart || myField.selectionStart === 0) {
                    var startPos = myField.selectionStart;
                    var endPos = myField.selectionEnd;
                    this.$nextTick(() => {
                        myField.selectionStart = 0;
                        myField.selectionEnd = startPos + myValue.length;
                    }); // 这句是重点, 圈起来
                    myField.focus();
                    myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
                }
            } catch (e) {}
        },
        InputMove(moveDirection, colcode, index) {
            if (moveDirection == "up") {
                var that = this;
                if (index == 1) {
                    that.$refs.inputbackreason.focus();
                    return false;
                }
                var focusIndex = index - 1;
                setTimeout(function() {
                    that.$refs["input" + focusIndex][0].focus();
                    if (["_dt", "_date", "pat_birth"].indexOf(that.$refs["input" + focusIndex][0].id) == -1) {
                        //  that.HightlightPos(that.$refs["input" + focusIndex][0].value, colcode, index);
                    } else {
                        that.$refs["input" + focusIndex][0].select();
                    }
                }, 1);
            } else {
                this.nextFocus(colcode, index);
            }
        },
        currentReqsheetChange({ row }) {
            if (row.req_sheetid) {
                this.queryReqsheetitems(row.req_sheetid);
            }
        },
        chooseReqsheet(type, data) {
            if (type == 1) { // 有数据修改回传
                console.log(data)
                this.reqitemchange(data);
            }
            this.dialogReqItem1 = false;
        },
        // filterreqlist(e) {
        //     this.allReqsheetList = [];
        //     if (e) {
        //         for (let i = 0; i < this.fallReqsheetList.length; i++) {
        //             let item = this.fallReqsheetList[i];
        //             if (item.inputcode.toUpperCase().indexOf(e.toUpperCase()) > -1 || item.req_itemname.toUpperCase().indexOf(e.toUpperCase()) > -1 || item.req_itemcode.toUpperCase().indexOf(e.toUpperCase()) > -1) {
        //                 this.allReqsheetList.push(item);
        //                 if (this.allReqsheetList.length >= 50) {
        //                     return;
        //                 }
        //             }
        //         }
        //     } else {
        //         for (let i = 0; i < this.fallReqsheetList.length; i++) {
        //             let item = this.fallReqsheetList[i];
        //             this.allReqsheetList.push(item);
        //             if (this.allReqsheetList.length >= 50) {
        //                 return;
        //             }
        //         }
        //     }
        // },
        clearRightData() {
            this.reqBack = {};
            this.masterParam = {
                pat_hospcode: XEUtils.clone(this.initHosp.pat_hospcode, true),
                pat_hospname: XEUtils.clone(this.initHosp.pat_hospname, true)
            };
            this.reqDetailList = [];
            this.$refs.rxTable.clearData();
            this.nodata = true;
            this.selectRow = {};
        },
    }
}
</script>

<style scoped>
table {
    font-size: 12px;
    border-collapse: separate;
    /* border-spacing: 5px; */
}
/deep/ .vxe-table .vxe-header--column {
    padding: 5px 0 !important;
    line-height: 15px !important;
}
.page-top {
    width: 100%;
    height: 70px;
    border: 1px solid #ccc;
    position: absolute;
    font-size: 12px;
    padding: 5px 0;
    line-height: 24px;
    overflow-x: auto;
    overflow-x: overlay;
}
::-webkit-scrollbar {
    width: 0px;
    height: 5px;
    border: 4px solid white;
}
::-webkit-scrollbar-thumb {
    background-color: #c1c1c1;
}
::-webkit-scrollbar-track {
    background-color: #f1f1f1;
}
.page-top-info {
    display: flex;
    margin-bottom: 5px;
}
.page-top .el-radio {
    margin-right: 10px;
}
.search-title {
    margin: 0 5px 0 10px;
}
.search-text {
    width: 135px;
}
.top-deal {
    height: 25px;
    margin-right: 5px;
    text-align: right;
}
.pagecenter {
    position: absolute;
    top: 75px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
    display: flex;
}
.pagecenter-left {
    height: 100%;
    width: calc(100% - 585px);
    padding-right: 5px;
}
.pagecenter-right {
    width: 580px;
}
.show-area {
    position: absolute;
    height: 100%;
    width: 580px;
    z-index: 1999;
    background: rgba(204, 204, 204, 0.2);
}
.req-select {
    display: inline-block;
    width: 180px;
    margin-right: 10px;
}
/deep/ .req-select .el-select {
    width: 100%;
}
/deep/ .table-bottom-content .vxe-table {
    height: 100%;
}
/deep/ .table-bottom-content .vxe-table .vxe-table--body-wrapper {
    height: calc(100% - 27px);
}
/deep/ .table-bottom-content .vxe-table--empty-block {
    height: calc(100% - 32px);
}
.column-item {
    padding: 0 5px 0 3px;
    display: table-cell;
}
.table2style table {
    border-spacing: 1px;
}
.table1style tr td {
    padding: 1px 2px 1px 2px;
}
.table2style tr td {
    padding: 0px 5px 0px 3px;
}
.el-checkbox__label {
    display: inline-block;
    padding-left: 2px;
    line-height: 19px;
    font-size: 14px;
}
/deep/.myclass > .table2style .el-input.is-disabled .el-input__inner {
    border-color: #e4e7ed;
    color: #c0c4cc;
    cursor: not-allowed;
}
/deep/ .myclass .el-input--suffix .el-input__inner {
    padding-right: 10px;
}
/deep/.myclass > .table2style .el-input--small .el-input__inner {
    height: 20px !important;
    line-height: 20px !important;
}
/deep/ .myclass > .table2style .el-input--small .el-input__icon {
    line-height: 18px !important;
}
</style>